﻿
using System.Windows;
using System.Windows.Controls;

namespace DualPlaneFR4Paster.Views.Dialogs
{
    /// <summary>
    /// PasswordDialog.xaml 的交互逻辑
    /// </summary>
    public partial class PasswordDialog : UserControl
    {
        public PasswordDialog()
        {
            InitializeComponent();
            psw.Focus();
        }
    }
    public class Test1
    {
        public static string GetPassword(DependencyObject obj)
        {
            return (string)obj.GetValue(PasswordProperty);
        }

        public static void SetPassword(DependencyObject obj, string value)
        {
            obj.SetValue(PasswordProperty, value);
        }

        // Using a DependencyProperty as the backing store for Password.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PasswordProperty =
            DependencyProperty.RegisterAttached("Password", typeof(string), typeof(Test1), new PropertyMetadata(null, new PropertyChangedCallback((s, e) => {
                var pwd = s as PasswordBox;
                //pwd.Password = e.NewValue.ToString();//Password我们一般不需要初始值
                pwd.PasswordChanged -= Pwd_PasswordChanged;
                pwd.PasswordChanged += Pwd_PasswordChanged;//输入变化事件
            })));

        private static void Pwd_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = sender as PasswordBox;
            SetPassword(passwordBox, passwordBox.Password);//把密码内容更新出去
        }
    }
}
